//定义处理方法
import { handleActions } from "redux-actions";
import _ from "lodash"
//从Types中拿到操作类型
import { USERS_SET_CURPAGE, USERS_SET_EACHPAGE, USERS_GET_USERS, } from "../types.js"

const InitialValue = {
    curPage: 1,
    eachPage: 5,
    total: 0,
    maxPage: 0,
    rows: [],
    Address:[]
}

// 拿到数据库中的用户列表


export const users_list = handleActions({
    // 将传入的数据存储到状态机
    [USERS_GET_USERS]: (state, { payload }) => {
        const { data } = payload
        return _.assign({}, state, data)
    },
    // 设置当前页码
    [USERS_SET_CURPAGE]: (state, { payload }) => {
        const { setcurpage } = payload
        return _.assign({}, state, { curPage: setcurpage })
    },
    // 设置每页显示的条数
    [USERS_SET_EACHPAGE]: (state, { payload }) => {
        const { seteachpage } = payload
        return _.assign({}, state, { eachPage: seteachpage })
    },
}, InitialValue);//用来创建reducer的,里面是具体处理函数 